#include <iostream>
using namespace std;

// Product interface

class Product
{
public:
    virtual ~Product() {}
    virtual std::string operatortion() const = 0;
};

// Concrete Products

class ConcreteProductA : public Product
{
public:
    std::string operatortion() const override
    {
        return "Result of ConcreteProductA";
    }
};

class ConcreteProductB : public Product
{
public:
    std::string operatortion() const override
    {
        return "Result of ConcreteProductB";
    }
};

// Creator interface
class Creator
{
public:
    virtual ~Creator() {}
    virtual Product *createProduct() const = 0;
    std::string someOperation() const
    {
        Product *product = this->createProduct();
        std::string result = "Creator: The same creator's code has just worked with " + product->operatortion();
        delete product;
        return result;
    }
};

class ConcreteCreatorA : public Creator
{
public:
    Product *createProduct() const override
    {
        return new ConcreteProductA();
    }
};

class ConcreteCreatorB : public Creator
{
public:
    Product *createProduct() const override
    {
        return new ConcreteProductB();
    }
};


// 简单工厂--根据不同的参数创建不同的产品
class SimpleFactory {
public:
    static Product* createProduct(const std::string& type) {
        if (type == "A") {
            return new ConcreteProductA();
        } else if (type == "B") {
            return new ConcreteProductB();
        }
        return nullptr;
    }
};



//根据调用对象不同创建不同的产品
int main(){
    Creator* creatorA=new ConcreteCreatorA();
    cout<<creatorA->someOperation()<<endl;
    delete creatorA;
    Creator* creatorB=new ConcreteCreatorB();
    cout<<creatorB->someOperation()<<endl;
    delete creatorB;
    return 0;
    return 0;
}